package com.example.apple.zyfypt_122zhaozy.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.apple.zyfypt_122zhaozy.R;
import com.example.apple.zyfypt_122zhaozy.iface.RegisterListener;
import com.example.apple.zyfypt_122zhaozy.model.RegisterModel;


public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{

    private EditText name, pwd,tel;
    private Button submit;

   RegisterListener registerListener = new RegisterListener() {
        @Override
        public void onResponse(String msg) {
            if(msg.equals("1")){
                System.out.println("result:"+msg);
                finish();
            }else{
                System.out.println("result:"+msg);
            }
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(RegisterActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        Toast.makeText(this, "Amicool注册", Toast.LENGTH_SHORT).show();
        init();

        Button button=(Button)findViewById(R.id.buttonfh);
        button.setOnClickListener(this);


    }

    private void init() {
        name = (EditText)findViewById(R.id.editTextuser);
        pwd = (EditText)findViewById(R.id.editTextpassword);
        tel = (EditText)findViewById(R.id.editTexttel);
        submit = (Button)findViewById(R.id.buttonreg);

        submit.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
    switch (v.getId())
        {
            case R.id.buttonfh:
                finish();
                break;
            case R.id.buttonreg:
                System.out.println("注册——提交");
                RegisterModel registerModel = new RegisterModel();
                registerModel.getResult(name.getText().toString(),
                        pwd.getText().toString(),
                        tel.getText().toString(),
                        registerListener);

        }
    }
}
